<?php

/**
 * Payment filter form base class.
 *
 * @package    erpcrm
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfPropelFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BasePaymentFormFilter extends BaseFormFilterPropel
{
  public function setup()
  {
    $this->setWidgets(array(
      'customer_iden'        => new sfWidgetFormPropelChoice(array('model' => 'AccountCustomer', 'add_empty' => true)),
      'payment_number'       => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'cash'                 => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'remarks'              => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'payment_type'         => new sfWidgetFormPropelChoice(array('model' => 'ListDocumentTypes', 'add_empty' => true, 'key_method' => 'getTypeid')),
      'transaction_type'     => new sfWidgetFormFilterInput(array('with_empty' => false)),
      'payment_invoice_list' => new sfWidgetFormPropelChoice(array('model' => 'Invoice', 'add_empty' => true)),
    ));

    $this->setValidators(array(
      'customer_iden'        => new sfValidatorPropelChoice(array('required' => false, 'model' => 'AccountCustomer', 'column' => 'contact_iden')),
      'payment_number'       => new sfValidatorPass(array('required' => false)),
      'cash'                 => new sfValidatorSchemaFilter('text', new sfValidatorNumber(array('required' => false))),
      'remarks'              => new sfValidatorPass(array('required' => false)),
      'payment_type'         => new sfValidatorPropelChoice(array('required' => false, 'model' => 'ListDocumentTypes', 'column' => 'typeid')),
      'transaction_type'     => new sfValidatorPass(array('required' => false)),
      'payment_invoice_list' => new sfValidatorPropelChoice(array('model' => 'Invoice', 'required' => false)),
    ));

    $this->widgetSchema->setNameFormat('payment_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    parent::setup();
  }

  public function addPaymentInvoiceListColumnCriteria(Criteria $criteria, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $criteria->addJoin(PaymentInvoicePeer::PAYMENT_IDEN, PaymentPeer::PAYMENT_IDEN);

    $value = array_pop($values);
    $criterion = $criteria->getNewCriterion(PaymentInvoicePeer::INVOICE_IDEN, $value);

    foreach ($values as $value)
    {
      $criterion->addOr($criteria->getNewCriterion(PaymentInvoicePeer::INVOICE_IDEN, $value));
    }

    $criteria->add($criterion);
  }

  public function getModelName()
  {
    return 'Payment';
  }

  public function getFields()
  {
    return array(
      'payment_iden'         => 'ForeignKey',
      'customer_iden'        => 'ForeignKey',
      'payment_number'       => 'Text',
      'cash'                 => 'Number',
      'remarks'              => 'Text',
      'payment_type'         => 'ForeignKey',
      'transaction_type'     => 'Text',
      'payment_invoice_list' => 'ManyKey',
    );
  }
}
